﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Collections.Specialized.BitVector32;

namespace Tools
{
    /// <summary>
    /// 读取appsettings.json文件类
    /// </summary>
    public class AppSettingHelper
    {
        private static IConfiguration _config;
        public AppSettingHelper(IConfiguration configuration)
            {
                _config = configuration;
            }

            /// <summary>
            /// 读取指定节点的字符串
            /// </summary>
            /// <param name="sessions"></param>
            /// <returns></returns>
            public static string ReadAppSettings(params string[] sessions)
            {
                try
                {
                    if (sessions.Any())
                    {
                        return _config[string.Join(":", sessions)];
                    }
                }
                catch
                {
                    return "";
                }
                return "";
            }

            /// <summary>
            /// 读取实体信息
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="session"></param>
            /// <returns></returns>
            public static List<T> ReadAppSettings<T>(params string[] session)
            {
                List<T> list = new List<T>();
                _config.Bind(string.Join(":", session), list);
                return list;
            }
        }
    }


